package com.party.core.service.information.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.information.InformationReadDao;
import com.party.core.dao.write.information.InformationWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.information.Information;
import com.party.core.service.information.IInformationService;
import com.sun.istack.NotNull;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @ClassName InformationService
 * @Description
 * @Author shenliuhai
 * @Date 2020/2/6 14:30
 **/
@Service
public class InformationService implements IInformationService {

    @Autowired
    private InformationReadDao informationReadDao;

    @Autowired
    private InformationWriteDao informationWriteDao;

    @Override
    public String insert(Information information) {
        BaseModel.preInsert(information);
        boolean result = informationWriteDao.insert(information);
        if (result){
            return information.getId();
        }
        return null;

    }

    @Override
    public boolean update(Information information) {
        information.setUpdateDate(new Date());
        return informationWriteDao.update(information);
    }

    @Override
    public boolean deleteLogic(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return informationWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return informationWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return informationWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return informationWriteDao.batchDelete(ids);
    }

    @Override
    public Information get(String id) {
        return informationReadDao.get(id);
    }

    @Override
    public List<Information> listPage(Information information, Page page) {
        return informationReadDao.listPage(information,page);
    }

    @Override
    public List<Information> list(Information information) {
        return informationReadDao.listPage(information,null);
    }

    @Override
    public List<Information> batchList(@NotNull Set<String> ids, Information information, Page page) {
        if (CollectionUtils.isEmpty(ids)){
            return Collections.EMPTY_LIST;
        }
        return informationReadDao.batchList(ids,new HashedMap(),page);
    }

    @Override
    public List<Information> webListPage(Information information, Map<String, Object> params, Page page) {
        return informationReadDao.webListPage(information,params,page);
    }

    @Override
    public List<Information> mobileListPage(Information information, Map<String, Object> params, Page page) {
        return informationReadDao.mobileListPage(information,params,page);
    }
}
